from collections import Counter
from typing import List


def substringWithAllWords(s: str, words: List[str]) -> List[int]:
    if not s or not words:
        return []
    word_count = len(words)
    word_len = len(words[0])
    substr_len = word_len * word_count
    target = Counter(words)
    end = len(s) - substr_len + 1
    res = []
    for pos_in_s in range(end):
        slices = []
        for word_ordinal in range(word_count):
            slice_start_pos = pos_in_s + word_len * word_ordinal
            slices.append(s[slice_start_pos: slice_start_pos + word_len])
        if target == Counter(slices):
            res.append(pos_in_s)
    return res


s = "barfoothefoobarman"
words = ["foo", "bar"]

print(substringWithAllWords(s, words))
